mini.parse();
//sss
var ue = UE.getEditor('container');
var mdname=mini.getbyName("mdname");
var form=new mini.Form("form1");

//px转换为rem
(function(doc, win) {
    var docEl = doc.documentElement,
        resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
        recalc = function() {
            var clientWidth = docEl.clientWidth;
            if (!clientWidth) return;
            if (clientWidth >= 640) {
                docEl.style.fontSize = '100px';
            } else {
                docEl.style.fontSize = 100 * (clientWidth / 640) + 'px';
            }
        };

    if (!doc.addEventListener) return;
    win.addEventListener(resizeEvt, recalc, false);
    doc.addEventListener('DOMContentLoaded', recalc, false);
})(document, window);

// 接收父页面传过来的值的方法
function SetData(data){
    data = mini.clone(data);       //将父页面传过来的值深克隆一下
    console.log(data.row);
    if(data.action=="edit"){      //当状态是edit的时候

        var id=data.row.id        //打点调用你获取要用的ID参数下面换成正确额得接口调用
        console.log(id);
         $.ajax({
             url: "http://localhost:8080/DSMP/moduleDeclaration/update.do",
             contentType: "application/json",
             type: "post",
             data: id,
             success: function (data) {//请求成功完成后要执行的方法
                 console.log(data);
                 // //富文本渲染值方式
                 // var text = "MiniUI - 专业WebUI控件库";
                 // editor.html(text);
                 // //文本框渲染值方式
                 // var text={mdname:"nihao"};
                 // mdname.setValue(text.mdname);
             },
             error: function (data) {
                 mini.alert(cuole);
             }
          })
    }else if(data.action=="new"){

    }
}



function imgChange(obj1, obj2) {
    //获取点击的文本框
    var file = document.getElementById("file");
    //存放图片的父级元素
    var imgContainer = document.getElementsByClassName(obj1)[0];
    //获取的图片文件
    var fileList = file.files;
    //文本框的父级元素
    var input = document.getElementsByClassName(obj2)[0];
    var imgArr = [];
    //遍历获取到得图片文件
    for (var i = 0; i < fileList.length; i++) {
        var imgUrl = window.URL.createObjectURL(file.files[i]);
        imgArr.push(imgUrl);
        var img = document.createElement("img");
        img.setAttribute("src", imgArr[i]);
        var imgAdd = document.createElement("div");
        imgAdd.setAttribute("class", "z_addImg");
        imgAdd.appendChild(img);
        imgContainer.appendChild(imgAdd);
    };
    imgRemove();
};

function imgRemove() {
    var imgList = document.getElementsByClassName("z_addImg");
    var mask = document.getElementsByClassName("z_mask")[0];
    var cancel = document.getElementsByClassName("z_cancel")[0];
    var sure = document.getElementsByClassName("z_sure")[0];
    for (var j = 0; j < imgList.length; j++) {
        imgList[j].index = j;
        imgList[j].onclick = function() {
            var t = this;
            mask.style.display = "block";
            cancel.onclick = function() {
                mask.style.display = "none";
            };
            sure.onclick = function() {
                mask.style.display = "none";
                t.style.display = "none";
            };

        }
    };
};

//保存按钮
function onsave() {
    // 校验
    form.validate();
    if (form.isValid() == false) return;
    alert("111");
    //获取富文本信息
    var arr = ue.getContent();
    console.log(arr);
    //获取textbox信息
    var mdname=mini.get("vCatalogName");
    var data=mdname.getValue();
    console.log(data);
    //获取上传图片信息
    // var formData = new FormData();
    // var imgList=document.getElementById("file").files;
    //
    //
    // console.log(imgList)
    // var imgLists = []
    // var formData = new FormData();
    // console.log(formData);
    // for (let i = 0; i < imgList.length; i++) {
    //     imgLists.push(imgList[i])
    //     formData.append('files', imgLists)
    // }
    // console.log(imgLists);
    // imgLists=JSON.stringify(imgLists);
    // console.log(formData);
     /*
     $.ajax({
         url: 'http://localhost:8080/DSMP/moduleDeclaration/add.do',
         type: 'POST',
         data: imgLists,
         processData: false,
         contentType: false,
         async: false,
         success: function(data) {
             console.log(data);
         }
     })
     */

}

